<%@ page language="java" contentType="text/html;charset=utf-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="my" uri="/mytaglibs"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD html 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Expires" content="0">
<title>单位</title>
<%@ include file="/common/jsinclude.jsp"%>
<script language="javascript">
var mygrid;
var varKeyValue="";
function fnLoad(){
	document.getElementById('gridbox').style.height = document.getElementById('idGrid').offsetHeight;
	mygrid = new dhtmlXGridObject('gridbox');
	mygrid.setImagePath("<%=request.getContextPath()%>/statics/dhtmlx/imgs/");
	mygrid.setHeader('<my:dhtmxgrid name="EntityUomGrid" field="headers" />');
	mygrid.setInitWidths('<my:dhtmxgrid name="EntityUomGrid" field="widths" />');
	mygrid.setColTypes('<my:dhtmxgrid name="EntityUomGrid" field="types" />');
	mygrid.setColSorting('<my:dhtmxgrid name="EntityUomGrid" field="sorts" />');
	mygrid.setColAlign('<my:dhtmxgrid name="EntityUomGrid" field="aligns" />');
	mygrid.setColumnColor("#efefef");
	mygrid.enableAlterCss("even","uneven");
	mygrid.setMultiselect(false);
	mygrid.enableTooltips("false");
	mygrid.attachEvent("onRowSelect",doOnRowSelected);
	mygrid.init();
	//mygrid.splitAt(3);
	query();
}
function doOnRowSelected(id){
	varKeyValue=mygrid.getUserData(mygrid.getSelectedId(),"key");
	setButtonStatus(false);
}
function fnGridFinish(){
	setButtonStatus(true);
	var vError=mygrid.getUserData("", "error");
	if(vError){
		alert("错误:"+vError);
	}
}
function setButtonStatus(status){
    var editButton = document.getElementById("btnEdit");
    var deleteButton = document.getElementById("btnRemove");
    if(editButton) editButton.disabled = status;
    if(deleteButton) deleteButton.disabled = status;
}
function create(){
    formList.action = "<%=request.getContextPath()%>/entityUom/edit.action";
    formList.submit();
}
function remove(){   
    if(varKeyValue == ""){
    	alert("请选择要删除的数据!");
        return;
    }
    if(confirm("警告:确定要删除此条记录?")){
    	var vURL="<%=request.getContextPath()%>/entityUom/remove.action";
		var vParams="requestway=ajax&key="+varKeyValue;
		dhtmlxAjax.post(vURL,encodeURI(vParams),function(loader){
			var text = loader.xmlDoc.responseText;
		    if (text == "success") {
				query();
			} else {
				alert(text);
			}
		});
    }
}
function edit(){
    if(varKeyValue == ""){
        alert("请选择要修改的数据!");
        return;
    }
    formList.action = "<%=request.getContextPath()%>/entityUom/edit.action?key="+varKeyValue;
    formList.submit();
}
function query(){
	var qryUrl = "<%=request.getContextPath()%>/entityUom/xmldatas.action";
	qryUrl+="?prepend=where";
	qryUrl+="&qryParamNames=pName|pAbbr";
qryUrl+="&qryLogicFields=k_entityuom.uomname|k_entityuom.uomabbr";
qryUrl+="&qryFieldTypes=str|str";
qryUrl+="&qryOperators=like|like";
qryUrl+="&pName="+encodeValue(formQuery.pName.value);
qryUrl+="&pAbbr="+encodeValue(formQuery.pAbbr.value);
	mygrid.clearAll();
	mygrid.loadXML(qryUrl,fnGridFinish);
}
</script>
</head>
<body onload="fnLoad()">
<table width="100%" height="100%" cellpadding="0" cellspacing="0" border="0">
<tr height="20px"><td>
<table width="100%" cellpadding="0" cellspacing="0" border="0" class="tabModule">
    <tr><td class="title">单位</td><td align="right" class="command">[管理]</td></tr>
</table>
<form name="formQuery" action="" method="POST" >
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="tabQuery">
<tr>
#makeQuickSearch()
</tr><tr>
<td nowrap align="right" colspan="8"> 
	<input title="Search [Alt+Q]" accessKey="Q" class="buttonOn" type="button" name="btnSearch" value="查询" onclick="query()" />
	<input title="Clear [Alt+C]"  accessKey="C" class="buttonOn" type="reset"  name="btnClear"  value="清空"/>
</td></tr>
</table>
</form>
<table width="100%" cellpadding="0" cellspacing="0" border="0" class="tabActions">
<tr>
    <td>
        <input class="buttonOn" type="button" name="btnAdd"    value="新增" onclick="create()">
        <input class="buttonOn" type="button" name="btnEdit"   value="修改" disabled onclick="edit()">
        <input class="buttonOn" type="button" name="btnRemove" value="删除" disabled onclick="remove()">
    </td>
</tr>
</table>
</td></tr>
<tr height="*%" valign="top" id="idGrid"><td>
	<table width="100%" height="100%" cellpadding="0" cellspacing="0" border="0" class="tabList">
		<tr>
			<td valign="top">
				<div id="gridbox" style="background-color:white;overflow:hidden;width:100%;"></div>
			</td>
		</tr>
	</table>
</td></tr>
</table>
<form name="formList" action="" method="POST">
<input type="hidden" name="command" value="">
</form>
</body>
<script language="javascript">

</script>
</html>